<template>
  <view>
    <!-- 微信小程序专用 -->

    <button @click="startPush">开始推流</button>
    <button @click="stopPush">停止推流</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      isWeixin: false,
      pushUrl: "rtmp://your_server/live/streamid", // 替换为真实地址
    };
  },
  onLoad() {
    // 判断平台
    this.isWeixin =
      uni.getSystemInfoSync().platform === "devtools" ||
      uni.getSystemInfoSync().platform === "ios" ||
      uni.getSystemInfoSync().platform === "android";
  },
  methods: {
    startPush() {
      // 微信小程序通过组件属性控制，无需额外代码
      uni.showToast({ title: "推流已开始", icon: "none" });
    },
    stopPush() {
      // 通过修改 url 为空停止推流
      this.pushUrl = "";
      uni.showToast({ title: "推流已停止", icon: "none" });
    },
    onPushStateChange(e) {
      console.log("状态变化:", e.detail.code);
      // 1001: 推流开始, 1002: 推流结束, 1003: 摄像头打开, etc.
    },
    onPushError(e) {
      console.error("推流错误:", e.detail.errMsg);
      uni.showToast({ title: "推流失败: " + e.detail.errMsg, icon: "none" });
    },
  },
};
</script>
